package com.hiznu.amap_flutter

import android.location.Location
import com.amap.api.fence.DistrictItem
import com.amap.api.fence.GeoFence
import com.amap.api.fence.PoiItem
import com.amap.api.location.AMapLocation
import com.amap.api.location.AMapLocationQualityReport
import com.amap.api.location.DPoint
import com.amap.api.maps.model.*
import com.autonavi.amap.mapcore.IPoint

val Location.data: Map<String, Any?>
    get() = mapOf(
        "accuracy" to accuracy,
        "altitude" to altitude,
        "speed" to speed,
        "timestamp" to (time.toDouble() / 1000),
        "latLng" to mapOf(
            "latitude" to latitude,
            "longitude" to longitude,
        ),
        "provider" to provider,
        "bearing" to bearing,
    )

val LatLng.data: Map<String, Any>
    get() = mapOf(
        "latitude" to latitude,
        "longitude" to longitude,
    )
val IPoint.data: Map<String, Any>
    get() = mapOf(
        "x" to x,
        "y" to y,
    )

val CameraPosition.data: Map<String, Any>
    get() = mapOf(
        "target" to target.data,
        "zoom" to zoom,
        "tilt" to tilt,
        "bearing" to bearing,
        "isAbroad" to isAbroad,
    )


val MarkerOptions.data: Map<String, Any?>
    get() = mapOf(
        "anchorU" to anchorU,
        "anchorV" to anchorV,
        "infoWindowOffsetX" to infoWindowOffsetX,
        "infoWindowOffsetY" to infoWindowOffsetY,
        "alpha" to alpha,
        "altitude" to altitude,
        "period" to period,
        "position" to position,
        "rotateAngle" to rotateAngle,
        "snippet" to snippet,
        "title" to title,
        "zIndex" to zIndex,
        "isDraggable" to isDraggable,
        "isVisible" to isVisible,
        "isFlat" to isFlat,
        "isInfoWindowAutoOverturn" to isInfoWindowAutoOverturn,
        "isInfoWindowEnable" to isInfoWindowEnable,
    )
val Marker.data: Map<String, Any?>
    get() = mapOf(
        "options" to options.data,
        "alpha" to alpha,
        "altitude" to altitude,
        "id" to id,
        "period" to period,
        "position" to position,
        "rotateAngle" to rotateAngle,
        "snippet" to snippet,
        "title" to title,
        "zIndex" to zIndex,
        "geoPoint" to geoPoint.data,
        "isRemoved" to isRemoved,
        "isClickable" to isClickable,
        "isDraggable" to isDraggable,
        "isVisible" to isVisible,
        "isFlat" to isFlat,
        "isViewMode" to isViewMode,
        "isInfoWindowAutoOverturn" to isInfoWindowAutoOverturn,
        "isInfoWindowEnable" to isInfoWindowEnable,
    )


val Poi.data: Map<String, Any>
    get() = mapOf(
        "latLng" to coordinate.data,
        "name" to name,
        "poiId" to poiId,
    )

val GeoFence.data: Map<String, Any?>
    get() = mapOf(
        "customID" to customId,
        "fenceID" to fenceId,
        "type" to type,
        "radius" to radius.toDouble(),
        "status" to status,
        "pointList" to pointList.map { points -> points.map { point -> point.data } },
        "center" to center.data,
        "poiItem" to poiItem?.data,
    )

val DistrictItem.data: Map<String, Any>
    get() = mapOf(
        "adCode" to adcode,
        "cityCode" to citycode,
        "districtName" to districtName,
        "pointList" to polyline.map { point -> point.data },
    )
val DPoint.data: Map<String, Any>
    get() = mapOf(
        "latitude" to latitude,
        "longitude" to longitude,
    )

val PoiItem.data: Map<String, Any>
    get() = mapOf(
        "latLng" to mapOf(
            "latitude" to latitude,
            "longitude" to longitude,
        ),
        "address" to address,
        "poiName" to poiName,
        "adName" to adname,
        "city" to city,
        "poiId" to poiId,
        "poiType" to poiType
    )

val AMapLocation.data: Map<String, Any?>
    get() = mapOf(
        "errorInfo" to errorInfo,
        "errorCode" to errorCode,
        "description" to description,
        "accuracy" to accuracy,
        "adCode" to adCode,
        "address" to address,
        "altitude" to altitude,
        "bearing" to bearing,
        "buildingId" to buildingId,
        "country" to country,
        "province" to province,
        "city" to city,
        "cityCode" to cityCode,
        "district" to district,
        "street" to street,
        "streetNum" to streetNum,
        "conScenario" to conScenario,
        "coordType" to coordType,
        "floor" to floor,
        "gpsAccuracyStatus" to gpsAccuracyStatus,
        "locationDetail" to locationDetail,
        "locationType" to locationType,
        "poiName" to poiName,
        "aoiName" to aoiName,
        "provider" to provider,
        "latitude" to latitude,
        "longitude" to longitude,
        "satellites" to satellites,
        "speed" to speed,
        "trustedLevel" to trustedLevel,
        "timestamp" to time.toDouble(),
        "locationQualityReport" to locationQualityReport.data,
    )

val AMapLocationQualityReport.data: Map<String, Any?>
    get() = mapOf(
        "adviseMessage" to adviseMessage,
        "gpsSatellites" to gpsSatellites,
        "gpsStatus" to gpsStatus,
        "netUseTime" to netUseTime,
        "networkType" to networkType,
        "isWifiAble" to isWifiAble,
        "isInstalledHighDangerMockApp" to isInstalledHighDangerMockApp,
    )